(function ($) {
    "use strict";

    /*==================================================================
    [ Focus Contact2 ]*/
    $('.input100').each(function () {
        $(this).on('blur', function () {
            if ($(this).val().trim() !== "") {
                $(this).addClass('has-val');
            } else {
                $(this).removeClass('has-val');
            }
        })
    })

    /*==================================================================
    [ Validate ]*/
    let input = $('.validate-input .input100');
    let check = true;
    $('.validate-form').on('submit', function () {
        for (let i = 0; i < input.length; i++) {
            if (validate(input[i]) === false) {
                showValidate(input[i]);
                check = false;
            }
        }

        return check;
    });


    $('.validate-form .input100').each(function () {
        $(this).focus(function () {
            hideValidate(this);
        });
    });

    function validate(input) {
        if ($(input).val().trim() === '') {
            return false;
        }
    }

    function showValidate(input) {
        let thisAlert = $(input).parent();

        $(thisAlert).addClass('alert-validate');
    }

    function hideValidate(input) {
        let thisAlert = $(input).parent();

        $(thisAlert).removeClass('alert-validate');
    }

    
    /*
    * 
    * ****************************弹窗 *************************************************
    * 
    * */
    
    /*初始化*/
    GrowlNotification.setGlobalOptions({
        buttons: {
            action: {
                text: 'Apply'
            },
            cancel: {
                text: 'Dismiss'
            }
        }
    });

    /*初始化选项*/
    function getOptions() {
        let position = 'bottom-right';
        let closeTimeout = '3000';
        let animation = 'slide';
        let showButtons = false;
        let showProgressBar = true;
        let animationOptions = {
            open: animation + '-in',
            close: animation + '-out'
        };

        if (animation === 'none') {
            animationOptions = {
                open: false,
                close: false
            };
        }
        return {
            description: 'I am a default notification',
            position: position,
            closeTimeout: closeTimeout,
            closeWith: ['click'],
            animation: animationOptions,
            showButtons: showButtons,
            buttons: {
                action: {
                    callback: function (notification) {
                        console.log('action button');
                    }
                }
            },
            showProgress: showProgressBar
        };
    }

    $('.login100-form-btn').on('click',function () {
        // 通过验证
        if (check) {
            // noinspection JSJQueryEfficiency
            let data = $('form').serializeArray();
            console.log(data);
            console.log(JSON.stringify(data));
            /*$.ajax({
                type:'POST',
                //提交的网址
                url:'/auth-h5',
                //提交的数据
                data: JSON.stringify(GetJsonData()),
                //参数格式为json
                contentType: "application/json; charset=utf-8",
                //返回数据的格式
                datatype: "json",
                //成功返回之后调用的函数
                success:function(data){

                },
                //调用出错执行的函数
                error: function(){

                }

            });
            let options = getOptions();
            options.title = 'Hello!';
            options.description = 'I am a default notification.';
            options.image = 'static/images/advice.png';
            options.image = {
                visible: true
            };
            GrowlNotification.notify(options);*/
            debugger
        }
    });



    /*
    *
    * ********************************验证码************************************
    *
    * */

    /*
    * 为了使每次生成图片不一致，即不让浏览器读缓存，所以需要加上时间戳
    * */
    function changeUrl(url) {
        let timestamp = (new Date()).valueOf();
        url = url.substring(0, 17);
        if ((url.indexOf("&") >= 0)) {
            url = url + "×tamp=" + timestamp;
        } else {
            url = url + "?timestamp=" + timestamp;
        }
        return url;
    }

    function changeImg() {
        let imgSrc = $("#img");
        let src = imgSrc.attr("src");
        imgSrc.attr("src", changeUrl(src));
    }

    $('#img').on('click',changeImg());


})(jQuery);